<template>
  <div class="wrap dashboard-editor-container"  id="app"  @mouseover="cmouseovered">
    <router-view ></router-view>
  </div>
  <!-- <el-dialog
    title="提示"
    width="30%"
    top="5vh"
    draggable
    :close-on-press-escape = false
    :close-on-click-modal	= false
    :show-close = false
    v-model="show"
  >
  <span style="color:#f36b6e;font-weight:600;text-align:center;">检测到您长时间无动作，请重新打开窗口</span>
  <template #footer>
    <el-button type="primary" @click="refresh">刷新</el-button>
  </template>
  </el-dialog> -->
</template>

<script>

export default {
  data() {
    return {
      // show: false,
      Username: '',
      timeOut: 2 * 60 * 60 * 1000 // 120 minutes
      // timeOut: 3000 // 120 minutes
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    if(!sessionStorage.getItem('Name')){
      this.$router.push('/')
    }
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    this.countTime()
    window.addEventListener('keydown', this.cmouseovered);
  },
  methods: {
    // refresh(){
    //   window.location.href = `${window.location.origin}/?#/AI?userid=${this.stringToBase64(sessionStorage.getItem('Name'))}`
    //   this.show = false
    // },
    // stringToBase64(str) {
    //   const encoder = new TextEncoder();
    //   const data = encoder.encode(str);
    //   const base64 = btoa(String.fromCharCode.apply(null, data));
    //   return base64;
    // },
    countTime() {
      this.timeOut = this.timeOut === 0 ? 1000000000000000 : this.timeOut
      const vm = this
      this.timer = setTimeout(function() {
        vm.logout()
      }, this.timeOut)
    },
    cmouseovered() {
      clearTimeout(this.timer)
      this.countTime()
    },
    async logout() {
      sessionStorage.clear();
      this.$router.push('/')
      // this.show = true
      // window.alert('检测到您长时间无动作，请重新打开窗口')
    },
  },
};
</script>

<style scoped lang="scss">
.wrap{
  flex-shrink: 0;
  display: flex;
  height: calc(100vh - 50px);
  background: #f0f2f5;
}
</style>